package com.yj.timecapsule.config;

import com.yj.timecapsule.interceptor.WebLoginInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Sean
 * @CreateTime 2024-07-31  13:04
 * @Description
 * @Version 1.0
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Resource
    private WebLoginInterceptor webLoginInterceptor;
    private static final String[] excludePath = new String[]{
            "/user/login",
            "/sms-code/**",

   };
    // 配置解决跨域
    @Override
    public void addCorsMappings(org.springframework.web.servlet.config.annotation.CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")
                .allowCredentials(false)
                .maxAge(3600);
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(webLoginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePath);

    }

}
